from analyze.xpath_analyzer import XpathAnalyzer
from basic.xpath_extractor import format_element


class QheeXpathAnalyzer(XpathAnalyzer):
    def personal(self, selector, task):
        rule_data = {
            'standard': '//div[@id="detail"]/div/div[contains(text(), "支持标准")]/following-sibling::div//text()',
            'standard_content': '//div[@id="detail"]/div/div[contains(text(), "支持内容")]/following-sibling::div//text()',
            'reporting_requirements': '//div[@id="detail"]/div/div[contains(text(), "申报要求")]/following-sibling::div//text()',
            'requirements': '//div[@id="detail"]/div/div[contains(text(), "具体要求")]/following-sibling::div//text()',
            'materials': '//div[@id="detail"]/div/div[contains(text(), "材料清单")]/following-sibling::div//text()',
            'procedure': '//div[@id="detail"]/div/div[contains(text(), "办理程序")]/following-sibling::div//text()',
            'according_to': '//div[@id="detail"]/div/div[contains(text(), "设定依据")]/following-sibling::div//text()',
            'attention_info': '//div[@id="detail"]/div/div[contains(text(), "注意事项")]/following-sibling::div//text()',
        }
        data = {}
        for k, v in rule_data.items():
            info = selector.xpath(v)
            info = "".join([each for each in info]).replace(u'\xa0', u' ')
            info = format_element(info)
            data[k] = info
        return data
